var WebSocketServer = require('ws').Server,
    wss = new WebSocketServer({ port: 8181 });
//客户端建立连接时触发的事件
wss.on('connection', function (ws) {
    console.log("someone conned");
    //接收到客户端消息时触发的事件
    ws.on('message', function (message) {

        message = JSON.parse(message);

        wss.clients.forEach(function (client) {
            client.send(message.user + " : " + message.msg);
        });

    });
});